<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //柯里化思想
      
        /*  const add=(arr)=>{
            return arr.reduce((sum,item)=>sum+=item,0)
        }
        const curry=(fn)=>{
            let arr=[]; 
            return  sum=(...b)=>{
                if(b.length>=1){
                    arr.push(b[0])
                    fn(arr)
                    return sum
                }
                return fn(arr)
            }
        }

        
        let addCurry = curry(add)
         console.log(addCurry(1)(2)(3)()) */
         function curry(fn,...args){
            if(args.length>=fn.length){
                return fn(...args)
            }else{
                return function(..._args){
                    return curry(fn,..._args,...args)
                }
            }
         }
         function fn(a,b,c,d,e){
            console.log(a+b+c+d+e)
         }
         const fn1=curry(fn)
         //fn1(1)(2)(3)(4)(5)
         fn1(1,2,3,4)(5)

    

/* 
         const add=(a,b,c)=>{
            return a+b+c
        }
        const curry=(fn)=>{
            return  inter=(...args)=>{
                if(args.length===fn.length)return fn(...args)
                return (...arg)=>inter(...arg,...args)
            }
        }

        
        let addCurry = curry(add)
         console.log(addCurry(1)(2)(3)) */


        //柯里化思想

        /* const getSum = (arr) => arr.reduce((pre, item) => pre + item)

        const getAdd = (...a) => {
            const fn = (...b) => getAdd(getSum(a) + getSum(b))
            fn.toString = () => getSum(a)
            return fn
        }
        console.log(Number(getAdd(4)(5)(8))) */
    </script>
    
</body>

</html>